package com.yxplearn.mybatisplus;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.yxplearn.mybatisplus.manager.PersistEntity;
import com.yxplearn.mybatisplus.pojo.User;

public class Test<T extends PersistEntity> {
    public static void main(String[] args) {
//        f();
//        g();
//		Test test = new Test();
//		System.out.println(test.getParameterizedType());
        removeTest();

        List<Integer> notifyTileIds = Arrays.asList(5, 4, 6).stream().sorted().collect(Collectors.toList());
        List<Integer> list = new ArrayList<>();
        list.add(5);
        list.add(4);
        list.add(6);
        list = list.stream().sorted().collect(Collectors.toList());
        System.out.println();
        list.forEach(System.out::print);
        System.out.println();
        notifyTileIds.forEach(System.out::print);
    }

    Class<T> parameterizedType;

    @SuppressWarnings("unchecked")
    Class<T> getParameterizedType() {
        User user = new User();
        if (parameterizedType == null) {
            Type genType = user.getClass().getGenericSuperclass();
            Type[] types = ((ParameterizedType) genType).getActualTypeArguments();
            parameterizedType = (Class<T>) types[0];
        }
        return parameterizedType;
    }

    public static void f() {
        String[] a = new String[2];
        Object[] b = a;
        a[0] = "hi";
        b[1] = Integer.valueOf(42);
    }

    public static void g() {
        List<String> a = new ArrayList<String>();
        List<Object> b = new ArrayList<Object>();
        a.add("hi");
        b.addAll(a);
        b.add(Integer.valueOf(42));
        System.out.println(b);
    }

    public static void removeTest() {
        List<Integer> integers = new ArrayList<>();
        integers.add(1);
        integers.add(2);
        integers.add(3);
        for (Integer i : integers) {
            integers.remove(i);
        }
    }
}
